package com.example.shortmessage.utils;

import android.content.Context;
import android.telephony.TelephonyManager;
import android.widget.Toast;

import static android.content.Context.TELEPHONY_SERVICE;

/**
 * 验证类
 * @author 27638
 */
public class ReadPhoneStatusUtils {
    /**
     * 验证sim状态
     * @return boolean
     */
    private  boolean validateSimCard(Context context) {
        TelephonyManager manager = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);
        switch (manager.getSimState()) {
            case TelephonyManager.SIM_STATE_READY:
                return true;
            case TelephonyManager.SIM_STATE_ABSENT:
                Toast.makeText(context,"请插入sim卡",Toast.LENGTH_LONG).show();
                return false;
            default:
                Toast.makeText(context,"sim卡被锁定或未知状态",Toast.LENGTH_LONG).show();
                return false;
        }
    }

    /**
     * 验证号码和内容
     *
     * @param phone
     * @param content
     * @return
     */
    public boolean validatePhone(Context context,String phone, String content) {
        boolean bool = true;
        if (validateSimCard(context)) {
            if (phone.length() == 0) {
                Toast.makeText(context,"电话号码不能为空！",Toast.LENGTH_LONG).show();
                bool = false;
            } else if (phone.length() <4) {
                Toast.makeText(context,"电话号码输入错误，请重新输入！",Toast.LENGTH_LONG).show();
                bool = false;
            } else if (content.length() == 0) {
                Toast.makeText(context,"短信内容不能为空！",Toast.LENGTH_LONG).show();
                bool = false;
            }
        }
        return bool;
    }

}
